package controller

import (
	service "camera_app/repository"
	"net/http"

	"github.com/gin-gonic/gin"
)

type PictureController struct {
	PicRepo *service.PictureRepository
}

func NewPictureController(pr *service.PictureRepository) *PictureController {
	return &PictureController{
		PicRepo: pr,
	}
}

func (pc *PictureController) SavePictureToBucket(ctx *gin.Context) {
	pc.PicRepo.SavePictureToBucket(ctx)
}

func (pc *PictureController) SharePics(ctx *gin.Context) {
	err := pc.PicRepo.SharePics(ctx)
	if err != nil {
		ctx.JSON(http.StatusBadRequest, gin.H{
			"code": 400,
			"msg":  "error",
			"data": err,
		})
	}
	ctx.JSON(http.StatusOK, gin.H{
		"code": 200,
		"msg":  "success",
		"data": nil,
	})
}

func (pc *PictureController) GetPics(ctx *gin.Context) {
	pics, err := pc.PicRepo.GetPicsByUser(ctx)
	if err != nil {
		ctx.JSON(http.StatusBadRequest, gin.H{
			"code": 400,
			"msg":  "error",
			"data": err,
		})
		return
	}
	ctx.JSON(http.StatusOK, gin.H{
		"code": 200,
		"msg":  "success",
		"data": pics,
	})
}
